<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入一个数字" class="ipt1" />
    <button>判断是否为对称数</button> <input type="text" class="ipt2" />
  </body>
</html>
<script>
  var oIpt1 = document.querySelector(".ipt1");
  var oBtn = document.querySelector("button");
  var oIpt2 = document.querySelector(".ipt2");
  oBtn.onclick = function () {
    var g = parseInt(oIpt1.value % 10);
    var s = parseInt((oIpt1.value % 100) / 10);
    var b = parseInt((oIpt1 % 1000) / 100);
    var q = parseInt(oIpt1.value / 1000);
    if (oIpt1.value.trim() == "") return alert("请输入内容");
    if (isNaN(oIpt1.value)) return alert("请输入数字");
    if (g == q && s == b) {
      oIpt2.value = "为对称数";
    } else {
      oIpt2.value = "非对称数";
    }
  };
</script>
